module.exports = function ($scope, $modalInstance, $resource, toaster, obj,  date2str){
    
	$scope.obj = obj;
	$scope.vm = {
		'data' : obj.release_time,
		'data1' : obj.release_end_time
	}

	$scope.options = {
		format: "YYYY-MM-DD HH:mm",
		locale : 'zh-cn',
		showClear: true
	}

    //保存
	$scope.save = function() {
		if(!checkInfo($scope.obj)) return;
		$scope.obj.release_time = $scope.vm.data.format('YYYY-MM-DD HH:mm');
		$scope.obj.release_end_time = $scope.vm.data1.format('YYYY-MM-DD HH:mm');
		$resource('/api/as/goc/infodiffusion/createinfo', {}, {}).save($scope.obj, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}
    
    //校验信息
	function checkInfo(obj){
		if(!$scope.vm.data){
			toaster.warning({title: '', body: '请填写自动发布时间.'});
			return false;
		}
		if(!$scope.vm.data1){
			toaster.warning({title: '', body: '请填写发布停止时间.'});
			return false;
		}
		return true;
	}
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }

};